/**    
  * 文件名：AmortizationRest.java</br>
 *    
 * 版本信息：v1.0</br>
 * 日期：2017年11月8日</br>
 * © 2005-2017 雷技信息科技（上海）有限公司版权所有</br>
 *
 */
package com.logic.landseaserver.models.rentalrate;

import java.util.HashMap;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.logic.common.enums.HttpCodeEnum;
import com.logic.common.util.CommonResult;
import com.logic.common.util.CommonResultMap;
import com.logic.common.util.QueryUtil;
import com.logic.landseaserver.common.exception.LandseaException;
import com.logic.landseaserver.common.util.LoggerHelper;
import com.logic.landseaserver.models.rentalrate.service.RentalRateService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 *
 * 项目名称：system-server</br>
 * 类名称：RentalRateRest</br>
 * 类描述：出租率报表</br>
 * 创建人：Aaron</br>
 * 创建时间：2018年4月28日 下午3:15:54</br>
 * 
 * @version 1.0
 *
 */
@Path("/RentalRate")
@Api(value = "出租率报表")
public class RentalRateRest
{
    private static final Logger LOGGER = LoggerFactory.getLogger(RentalRateRest.class);
    
    @Autowired
    private RentalRateService rentalRateService;
    
    /**
     * 
     * [简要描述]：分页查询</br>
     * [详细描述]：</br>
     * [作者]：Aaron(2017-11-08)</br>
     *
     * @param request
     * @return
     *
     */
    @POST
    @Path("/rentalRateList")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "查询出租率报表")
    public Response rentalRateList(@ApiParam(value = "param", required = true) QueryUtil queryUtil)
    {
        CommonResultMap map = new CommonResultMap();
        
        try
        {
            queryUtil.getPagingTool().calculateStartIndex();
            Object result = rentalRateService.pageList(queryUtil, true);
            Integer totalCount = queryUtil.getPagingTool().getTotalNum();
            map.setResultTotalCount(totalCount);
            map.setData(result);
            map.setResult(CommonResult.SUCCESS);
        }
        catch (LandseaException e)
        {
            LoggerHelper.handleException(LOGGER, "rentalRateList", e, map);
        }
        
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
    
    @POST
    @Path("/rentalRateExcel")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "导出出租率报表")
    public Response rentalRateExcel(@ApiParam(value = "param", required = true) QueryUtil queryUtil)
    {
        CommonResultMap map = new CommonResultMap();
        try
        {
            String url = rentalRateService.exportExcel(queryUtil);
            HashMap<String, String> resultmap = new HashMap<String, String>();
            resultmap.put("url", url);
            map.setData(resultmap);
            map.setResult(CommonResult.SUCCESS);
        }
        catch (LandseaException e)
        {
            LoggerHelper.handleException(LOGGER, "rentalRateExcel", e, map);
        }
        return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
    }
}
